using System;
using System.Collections.Generic;
using Windy.Transformations;
using System.ComponentModel.Composition;

namespace Windy.DragonCurve.Models.Schemes
{
    /// <summary>
    /// Sierpinski Triangle
    /// 
    /// The Sierpinski triangle drawn using an L-system.
    /// variables : X Y
    /// constants : + −
    /// start  : X
    /// rules  : (X → Y−X−Y), (Y → X+Y+X)
    /// angle  : 60°
    /// Here, X and Y both mean "draw forward", + means "turn left by angle", and − means "turn right by angle" (see turtle graphics). The angle changes sign at each iteration so that the base of the triangular shapes are always in the bottom (they would be in the top and bottom, alternatively, otherwise).
    /// </summary>
    [Export(typeof(DragonCurveScheme))]
    public class SierpinskiTriangleScheme : DragonCurveScheme
    {
        public SierpinskiTriangleScheme()
        {
            this.SetupName("Sierpinski Triangle")
                .SetupInitialSymbols(Symbols.X)
                .SetupCurveRules
                (
                    new ReplaceTransformRule<Symbols, LinkedListNode<Symbols>, Symbols>(Symbols.Plus, Symbols.Plus),
                    new ReplaceTransformRule<Symbols, LinkedListNode<Symbols>, Symbols>(Symbols.Minus, Symbols.Minus),
                
                    new ExpandTransformRule<Symbols, LinkedListNode<Symbols>, Symbols>(Symbols.X,
                            Symbols.Y, Symbols.Minus, Symbols.X, Symbols.Minus, Symbols.Y),
                    new ExpandTransformRule<Symbols, LinkedListNode<Symbols>, Symbols>(Symbols.Y,
                            Symbols.X, Symbols.Plus, Symbols.Y, Symbols.Plus, Symbols.X)
                )
                .SetupPlotRules(DragonCurvePlotRules.PlotingVariablePlotingRules)
                .SetupStepAngelDegree(60);
        }
    }


}
